package leo
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.system.Security;
	
	import leo.game.stage.BaseStage;
	import leo.game.stage.Game;
	import leo.game.ui.UIInitLoading;
	import leo.manager.LoaderManager;

	[SWF(width="768",height="640",frameRate="24",backgroundColor=0)]
	public class TDGame extends Sprite
	{
		public static var instance :TDGame;
		public var curStage :BaseStage = null;
		public function TDGame()
		{
			Security.allowDomain("*");
			TDGame.instance = this;
			
			if(stage)
			{
				init();
				stage.scaleMode = StageScaleMode.EXACT_FIT;
//				stage.align = StageAlign.LEFT;
//				stage.scaleMode = StageScaleMode.NO_SCALE;
				
			}else
			{
				addEventListener(Event.ADDED_TO_STAGE,init);
			}
			
		}
		/**
		 * 设置舞台显示内容 
		 * @param newStage
		 * 
		 */		
		public function setStage(newStage :BaseStage):void
		{
			addChild(newStage);
			
			if(curStage)
			{
				curStage.destory();
				if(curStage.parent)
				{
					curStage.parent.removeChild(curStage);
				}
			}
			
			curStage = newStage;
		}
		
		private function init(event :* = null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE,init);
			setStage(new UIInitLoading());
		}
		
	}
}